<template>
  <div class="window" :style="{ width: width + 'px' }" v-if="show">
    <div class="title">
      <span class="iconfont icon-back" @click="close"></span>
    </div>
    <div class="body">
      <slot></slot>
    </div>
    <div class="footer">
      <template v-if="(buttons && buttons.length > 0) || showCancer">
        <el-button link @click="close" v-if="showCancer">取消</el-button>
        <el-button
          v-for="btn in buttons"
          :type="btn.type"
          @click="btn.click"
          size="default"
          :key="btn.text"
          >{{ btn.text }}</el-button
        >
      </template>
    </div>
  </div>
</template>

<script setup>
import { ref } from "vue";
const width = window.innerWidth - 280;
const props = defineProps({
  buttons: {
    type: Array,
  },
  showCancer: {
    type: Boolean,
    default: true,
  },
  show: {
    type: Boolean,
    default: false,
  },
});
// 隐藏window需要父组件来做，因此要emit一个信号让父组件知道，进而调用相应的方法
const emit = defineEmits();
const close = () => {
  //   props.show = false;
  emit("close");
};
</script>

<style lang="scss" scoped>
.window {
  position: absolute;
  top: 0px;
  left: 0px;
  width: 100%;
  height: calc(100vh - 70px);
  background: #fff;
  z-index: 3;
  .title {
    height: 40px;
    display: flex;
    align-items: center;
    padding-left: 15px;
    .icon-back {
      font-size: 17px;
      cursor: pointer;
    }
  }
  .body {
    height: calc(100vh - 180px);
    padding: 15px;
    // overflow: auto;
    // background: greenyellow;
  }
  .footer {
    border-top: 1px solid #ddd;
    text-align: center;
    line-height: 70px;
  }
}
</style>
